package com.woniu.dao;

import com.woniu.controller.form.CompanyCount;
import com.woniu.controller.form.UserCount;
import com.woniu.model.BmsTreasureCount;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 平台资产表 Mapper 接口
 * </p>
 *
 * @author Kevin Kwok
 * @since 2021-04-13
 */
public interface BmsTreasureCountMapper extends BaseMapper<BmsTreasureCount> {
    //查询用户的消费记录
    @Select("select eu.username,ep.product_name,eo.price,ep.mode,eo.id,eo.deadline from e_user eu join e_order eo on eu.id=eo.uid join e_product ep on ep.id = eo.pid where eo.order_status=2 and eu.id = #{uid}")
    List<UserCount> userCount(Integer uid);

    //查询用户的消费总金额
    @Select("select sum(eo.price) as total from e_user eu join e_order eo on eu.id=eo.uid join e_product ep on ep.id = eo.pid where eo.order_status=2 and eu.id = #{uid}")
    int countAllConsumed(Integer uid);
    @Select("select eo.id,btc.amount,btc.time,btc.type,eu.username,eo.price from bms_treasure_count btc join e_order eo on btc.oid = eo.id join e_user eu on eu.id = eo.uid where btc.type=#{type}")
    List<CompanyCount> queryAllTreasure(String type);

    @Select("select sum(btc.amount) from bms_treasure_count btc join e_order eo on btc.oid = eo.id join e_user eu on eu.id = eo.uid where btc.type=#{type}")
    int countAllTreasure(String type);
}
